package org.drushpal.model
{
	import flash.net.SharedObject;
	import flash.net.registerClassAlias;
	
	import org.drushpal.model.vo.Settings;
	import org.robotlegs.mvcs.Actor;
	
	public class SettingsModel extends Actor
	{
		
		private var storageSettings:SharedObject;
		
		[Bindable]
		public var settings:Settings;
		
		public function SettingsModel()
		{
			registerClassAlias("Settings",Settings);
			loadSettings();
			
		}
		
		private function loadSettings():void{
			storageSettings = SharedObject.getLocal("settings");
			if(storageSettings.size && 
				storageSettings.data && 
				storageSettings.data.settings){
				settings = storageSettings.data.settings as Settings;
			}else{
				settings = new Settings();
			}
		}
		
		public function saveSettings():void{
			var storageSettings:SharedObject = SharedObject.getLocal("settings");
			storageSettings.data.settings = settings;
			storageSettings.flush();
		}
	}
}